﻿<Window x:Class="FacebookClient.MiniModeWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Facebook="clr-namespace:Contigo;assembly=Contigo"
    xmlns:FacebookClient="clr-namespace:FacebookClient"
    xmlns:ClientManager="clr-namespace:ClientManager"
    xmlns:ClientManagerControls="clr-namespace:ClientManager.Controls"
    xmlns:ClientManagerView="clr-namespace:ClientManager.View"
    xmlns:shell="clr-namespace:Microsoft.Windows.Shell;assembly=Microsoft.Windows.Shell"
    x:Name="MainWindow"
    FacebookClient:MiniModeWindow.NonGlassBackground="{DynamicResource FacebookBlueBrush}"
    Title="fishbowl" 
    ResizeMode="CanMinimize"
    WindowStyle="None"
    Width="280" Height="180"
    Topmost="True"
    AllowDrop="True"
    MouseLeftButtonDown="_OnMouseDown" 
    PreviewKeyDown="Grid_PreviewKeyDown" 
    MouseWheel="OnWindow_MouseWheel"
    IsVisibleChanged="_IsVisibleChanged">
  <shell:TaskbarItemInfo.TaskbarItemInfo>
    <shell:TaskbarItemInfo 
        Overlay="{Binding ElementName=NotificationCountControl, Path=ImageSource}"
        Description="{Binding ElementName=PART_ZapScroller2, Path=CurrentItem.Message}" ThumbnailClipMargin="0,0,0,33">
      <shell:TaskbarItemInfo.ThumbButtonInfos>
                <shell:ThumbButtonInfo Command="MediaCommands.PreviousTrack" CommandTarget="{Binding ElementName=RootPanel}">
          <shell:ThumbButtonInfo.ImageSource>
            <DrawingImage Drawing="{DynamicResource LeftArrowLightToolbarDrawing}"/>
          </shell:ThumbButtonInfo.ImageSource>
        </shell:ThumbButtonInfo>
                <shell:ThumbButtonInfo Command="MediaCommands.NextTrack"  CommandTarget="{Binding ElementName=RootPanel}">
          <shell:ThumbButtonInfo.ImageSource>
            <DrawingImage Drawing="{DynamicResource RightArrowLightToolbarDrawing}"/>
          </shell:ThumbButtonInfo.ImageSource>
        </shell:ThumbButtonInfo>
      </shell:TaskbarItemInfo.ThumbButtonInfos>
    </shell:TaskbarItemInfo>
  </shell:TaskbarItemInfo.TaskbarItemInfo>

  <Window.Resources>
    <FacebookClient:AddConverter x:Key="AddConverter" />

    <Style x:Key="CaptionButtonStyle" TargetType="{x:Type Button}">
      <Setter Property="SnapsToDevicePixels" Value="True"/>
      <Setter Property="OverridesDefaultStyle" Value="True"/>
      <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type Button}">
            <Grid>
              <Border x:Name="hover"
                  Background="Silver"
                  BorderBrush="White"
                  BorderThickness="1"
                  CornerRadius="3"
                  Margin="0,-4,0,0"
                  Opacity="0"/>
              <ContentPresenter Margin="3,1" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Grid>
            <ControlTemplate.Triggers>
              <Trigger Property="IsMouseOver" Value="True">
                <Trigger.EnterActions>
                  <BeginStoryboard>
                    <Storyboard>
                      <DoubleAnimation
                                  Duration="0:0:0.3"
                                  Storyboard.TargetName="hover"
                                  Storyboard.TargetProperty="Opacity"
                                  To=".45"/>
                    </Storyboard>
                  </BeginStoryboard>
                </Trigger.EnterActions>
                <Trigger.ExitActions>
                  <BeginStoryboard>
                    <Storyboard>
                      <DoubleAnimation
                                  Duration="0:0:0.3"
                                  Storyboard.TargetName="hover"
                                  Storyboard.TargetProperty="Opacity"
                                  To="0"/>
                    </Storyboard>
                  </BeginStoryboard>
                </Trigger.ExitActions>
              </Trigger>
            </ControlTemplate.Triggers>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

    <Style x:Key="MiniNotificationsToggleButtonStyle" TargetType="{x:Type ToggleButton}">
      <Style.Triggers>
        <DataTrigger Binding="{Binding Source={x:Static ClientManager:ServiceProvider.ViewManager}, Path=Notifications.Count}" Value="0">
          <Setter Property="Visibility" Value="Collapsed" />
        </DataTrigger>
      </Style.Triggers>
      <Setter Property="Cursor" Value="Hand" />
      <Setter Property="SnapsToDevicePixels" Value="True" />
      <Setter Property="OverridesDefaultStyle" Value="True" />
      <Setter Property="FocusVisualStyle" Value="{x:Null}" />
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type ToggleButton}">
            <Grid x:Name="Root">
              <ContentPresenter Margin="0,0" HorizontalAlignment="Center" VerticalAlignment="Center" />
            </Grid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </Window.Resources>

  <!-- Tricks with WS_THICKFRAME cause the window's template to not correspond to the true client size.
       We'll correct for this in the code-behind. -->
  <Grid x:Name="RootPanel" VerticalAlignment="Center" HorizontalAlignment="Stretch" Background="{Binding ElementName=MainWindow, Path=Background}">
    <Border Background="#44000000" CornerRadius="8"/>
    
    <DockPanel Margin="0">
      <DockPanel DockPanel.Dock="Bottom" Height="28" Margin="8">
        <ToggleButton x:Name="MiniNotificationsButton" 
            DockPanel.Dock="Right" 
                      Margin="3,0" 
                      Background="Transparent" 
                      Width="24" Height="24" 
                      VerticalAlignment="Center" 
                      HorizontalAlignment="Center" 
                      ToolTip="Show Notifications"
                      Style="{DynamicResource MiniNotificationsToggleButtonStyle}">
          <FacebookClient:NotificationCountControl x:Name="NotificationCountControl" DisplayCount="{Binding Source={x:Static ClientManager:ServiceProvider.ViewManager}, Path=Notifications.Count}">
            <FacebookClient:NotificationCountControl.Background>
              <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                <GradientStop Color="#e25423" Offset="0" />
                <GradientStop Color="#dc2300" Offset="1" />
              </LinearGradientBrush>
            </FacebookClient:NotificationCountControl.Background>
          </FacebookClient:NotificationCountControl>
        </ToggleButton>

        <Popup DockPanel.Dock="Right" Margin="1" x:Name="PART_PopupNotification" AllowsTransparency="True" IsOpen="{Binding ElementName=MiniNotificationsButton,Path=IsChecked}" PlacementTarget="{Binding ElementName=MainWindow}" Placement="Bottom">
          <Border x:Name="DropDownBorder" Background="#FF7489B6" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1">
            <FacebookClient:NotificationsControl 
              Grid.Row="1"
              VerticalAlignment="Top" 
              HorizontalAlignment="Right" 
              IsDisplayed="{Binding ElementName=MiniNotificationsButton, Path=IsChecked, Mode=TwoWay}" 
              RequestNavigate="_OnRequestNavigate" />
          </Border>
        </Popup>

        <Button DockPanel.Dock="Right" Margin="3,1" ToolTip="Go to Facebook" Style="{StaticResource SimpleButtonStyle}" Click="_OnFacebookButtonClick">
          <Rectangle Width="20" Height="20"  Fill="{StaticResource FacebookLogoLightDrawingBrush}" />
        </Button>

        <DockPanel VerticalAlignment="Center" HorizontalAlignment="Left" Margin="3">
          <RepeatButton 
              DockPanel.Dock="Left"
              Command="MediaCommands.PreviousTrack"
              Style="{DynamicResource SimpleButtonBaseStyle}"
              Width="18"
              Height="16"
              Margin="5,0"
              VerticalAlignment="Center"
              ToolTip="Previous slide">
            <Rectangle Fill="{DynamicResource LeftArrowLightToolbarDrawingBrush}"/>
          </RepeatButton>

          <ToggleButton
              DockPanel.Dock="Right"
              IsChecked="{Binding ElementName=PART_ZapScroller2, Path=IsShuffled}" 
              Style="{DynamicResource SimpleButtonBaseStyle}">
            <ToggleButton.Template>
              <ControlTemplate TargetType="{x:Type ButtonBase}">
                <Grid>
                  <Ellipse x:Name="ShuffleGlow" Fill="#88FFFFFF" Margin="2,2" >
                    <Ellipse.Effect>
                      <BlurEffect Radius="4"/>
                    </Ellipse.Effect>
                  </Ellipse>
                  <Rectangle x:Name="ShuffleShape" Margin="5,1" Width="18" Height="18" ToolTip="Stop Shuffling" Fill="{DynamicResource ShuffleLightToolbarDrawingBrush}"/>
                </Grid>
                <ControlTemplate.Triggers>
                  <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked}" Value="False">
                    <Setter TargetName="ShuffleGlow" Property="Opacity" Value="0" />
                    <Setter TargetName="ShuffleShape" Property="ToolTip" Value="Shuffle"/>
                  </DataTrigger>
                </ControlTemplate.Triggers>
              </ControlTemplate>
            </ToggleButton.Template>
          </ToggleButton>

          <ToggleButton
              DockPanel.Dock="Right"
              IsChecked="{Binding ElementName=PART_ZapScroller2, Path=IsPlaying, Mode=TwoWay}" 
              Style="{DynamicResource SimpleButtonBaseStyle}"
              Command="MediaCommands.TogglePlayPause"
              VerticalAlignment="Center">
            <ToggleButton.Template>
              <ControlTemplate TargetType="{x:Type ToggleButton}">
                <Rectangle x:Name="PlayPauseShape" 
                    Width="20" 
                    Height="20" 
                    VerticalAlignment="Center" 
                    HorizontalAlignment="Center" 
                    Margin="5,0"
                    ToolTip="Pause"
                    Fill="{DynamicResource PauseLightToolbarDrawingBrush}"/>
                <ControlTemplate.Triggers>
                  <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked}" Value="False">
                    <Setter TargetName="PlayPauseShape" Property="Fill" Value="{DynamicResource PlayArrowLightToolbarDrawingBrush}"/>
                    <Setter TargetName="PlayPauseShape" Property="ToolTip" Value="Play"/>
                  </DataTrigger>
                </ControlTemplate.Triggers>
              </ControlTemplate>
            </ToggleButton.Template>
          </ToggleButton>
            
          <RepeatButton 
              DockPanel.Dock="Right"
              Command="MediaCommands.NextTrack"
              Style="{DynamicResource SimpleButtonBaseStyle}"
              Height="16" Width="18"
              Margin="5,0"
              VerticalAlignment="Center"
              ToolTip="Next slide">
            <Rectangle Fill="{DynamicResource RightArrowLightToolbarDrawingBrush}"/>
          </RepeatButton>
          
          <TextBlock
              MinWidth="75" 
              HorizontalAlignment="Stretch" 
              VerticalAlignment="Center"
              TextAlignment="Center"
              Margin="3" 
              FontSize="{DynamicResource MiddleFontSize}"
              FontWeight="Medium"
              Foreground="White"
              FontFamily="{DynamicResource SansSerifFont}" >
            <TextBlock.Style>
              <Style TargetType="{x:Type TextBlock}">
                <Setter Property="Text">
                  <Setter.Value>
                    <MultiBinding StringFormat="{}{0} of {1}">
                      <Binding Converter="{StaticResource AddConverter}" ConverterParameter="1" ElementName="PART_ZapScroller2" Path="CurrentItemIndex" />
                      <Binding ElementName="PART_ZapScroller2" Path="ItemCount" />
                    </MultiBinding>
                  </Setter.Value>
                </Setter>
                <Style.Triggers>
                  <DataTrigger Binding="{Binding ElementName=PART_ZapScroller2, Path=ItemCount}" Value="0">
                    <Setter Property="Text" Value="Loading..."/>
                  </DataTrigger>
                </Style.Triggers>
              </Style>
            </TextBlock.Style>
          </TextBlock>
        </DockPanel>
      </DockPanel>

      <Grid>
        <FacebookClient:ZapScroller x:Name="PART_ZapScroller2" 
            HorizontalAlignment="Stretch" 
            VerticalAlignment="Stretch" 
            ItemsSource="{Binding Source={x:Static ClientManager:ServiceProvider.ViewManager}, Path=NewsFeed}"
            PlayTimeInterval="6000" IsPlaying="False" IsShuffled="False">
          <FacebookClient:ZapScroller.ItemTemplate>
            <DataTemplate>
              <Grid Margin="8,2">
                <Grid.RowDefinitions>
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="Auto" />
                  <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <!-- Large right margin because this is inline with the caption buttons. -->
                <FacebookClient:ContactNameDisplayControl Foreground="White" IsEnabled="False" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" FacebookContact="{Binding Actor}" Margin="0,0,60,0" />

                <FacebookClient:FriendButton 
                   Friend="{Binding Actor}"
                    Style="{DynamicResource SmallFriendButtonStyle}"
                    Grid.Row="1" Grid.Column="0" Margin="5,3,0,0"
                    VerticalAlignment="Top"
                    Click="_OnNavigateToContentButtonClicked" 
                    ClientManagerView:ViewManager.NavigationContent="{Binding Actor}"/>

                <Button Grid.Row="2" Grid.Column="0" 
                    VerticalAlignment="Center" 
                    HorizontalAlignment="Right" 
                    Click="_OnNavigateToContentButtonClicked" 
                    ClientManagerView:ViewManager.NavigationContent="{Binding Attachment}"
                    Style="{DynamicResource AnimatedItemButton}">
                  <Image Width="24" Height="24" Stretch="Uniform">
                    <Image.Style>
                      <Style TargetType="{x:Type Image}">
                        <Setter Property="Source" Value="{x:Null}" />
                        <Style.Triggers>
                          <DataTrigger Binding="{Binding Attachment.Type}" Value="Photos">
                            <Setter Property="Source" Value="pack://application:,,,/Resources/Images/Icons/photos_icon.png" />
                          </DataTrigger>
                          <DataTrigger Binding="{Binding Attachment.Type}" Value="Links">
                            <Setter Property="Source" Value="pack://application:,,,/Resources/Images/Icons/links_icon.png" />
                          </DataTrigger>
                          <DataTrigger Binding="{Binding Attachment.Type}" Value="Video">
                            <Setter Property="Source" Value="pack://application:,,,/Resources/Images/Icons/video_icon.png" />
                          </DataTrigger>
                        </Style.Triggers>
                      </Style>
                    </Image.Style>
                  </Image>
                </Button>

                <Grid Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" Margin="10" VerticalAlignment="Top">
                  <Path Fill="#FFE3E7F0" Stretch="Fill" Stroke="#FFE3E7F0" HorizontalAlignment="Left" Margin="-5,10,0,0" Width="20" Height="20" Data="M0,0 10,2 10,6Z" StrokeThickness="3" VerticalAlignment="Top" />

                  <Border VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,2,2,2" MinHeight="40" Background="#FFE3E7F0" CornerRadius="10" Padding="0">
                    <DockPanel>
                      <TextBlock DockPanel.Dock="Bottom" Margin="10,2" Style="{StaticResource CreatedTextBlockStyle}" Text="{Binding Created, Converter={StaticResource DateTimeConverter}}" />
                      <TextBlock DockPanel.Dock="Top" IsHyphenationEnabled="True" Padding="8,5" TextTrimming="WordEllipsis" TextWrapping="Wrap" FontSize="{DynamicResource MiddleFontSize}" Foreground="Black" FontFamily="{DynamicResource SerifFont}">
                        <TextBlock.Style>
                          <Style TargetType="{x:Type TextBlock}">
                            <Setter Property="Visibility" Value="Visible" />
                            <Style.Triggers>
                              <DataTrigger Binding="{Binding Message}" Value="">
                                <Setter Property="Visibility" Value="Collapsed" />
                              </DataTrigger>
                            </Style.Triggers>
                          </Style>
                        </TextBlock.Style>
                        <FacebookClient:HyperlinkTextContent Text="{Binding Message}" RequestNavigate="_OnRequestNavigate"  />
                      </TextBlock>

                      <Grid DataContext="{Binding Attachment}" Margin="14,4" VerticalAlignment="Top" HorizontalAlignment="Center">
                        <Button HorizontalAlignment="Left" 
                                Click="_OnNavigateToContentButtonClicked"
                                ClientManagerView:ViewManager.NavigationContent="{Binding}" 
                                IsEnabled="True">
                          <Button.Style>
                            <Style TargetType="Button" BasedOn="{StaticResource AnimatedItemButton}">
                              <Setter Property="Visibility" Value="Collapsed" />
                              <Style.Triggers>
                                <DataTrigger Binding="{Binding Type}" Value="Video">
                                  <Setter Property="Visibility" Value="Visible" />
                                </DataTrigger>
                              </Style.Triggers>
                            </Style>
                          </Button.Style>
                          <ClientManagerControls:FacebookImageControl FacebookImage="{Binding VideoPreviewImage}" FacebookImageDimensions="Small">
                            <ClientManagerControls:FacebookImageControl.Template>
                              <ControlTemplate TargetType="{x:Type ClientManagerControls:FacebookImageControl}">
                                <Image Margin="2" Stretch="Uniform" Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSource}" />
                              </ControlTemplate>
                            </ClientManagerControls:FacebookImageControl.Template>
                          </ClientManagerControls:FacebookImageControl>
                        </Button>

                        <Button ClientManagerView:ViewManager.NavigationContent="{Binding}"
                                Click="_OnNavigateToContentButtonClicked"
                                IsEnabled="True">
                          <Button.Style>
                            <Style TargetType="Button" BasedOn="{StaticResource AnimatedItemButton}">
                              <Setter Property="Visibility" Value="Collapsed" />
                              <Style.Triggers>
                                <DataTrigger Binding="{Binding Type}" Value="Photos">
                                  <Setter Property="Visibility" Value="Visible" />
                                </DataTrigger>
                              </Style.Triggers>
                            </Style>
                          </Button.Style>

                          <ClientManagerControls:FacebookImageControl FacebookImage="{Binding Photos[0].Image}" FacebookImageDimensions="Small">
                            <ClientManagerControls:FacebookImageControl.Template>
                              <ControlTemplate TargetType="{x:Type ClientManagerControls:FacebookImageControl}">
                                <Image Stretch="Uniform" Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSource}" />
                              </ControlTemplate>
                            </ClientManagerControls:FacebookImageControl.Template>
                          </ClientManagerControls:FacebookImageControl>
                        </Button>

                        <Grid>
                          <Button ClientManagerView:ViewManager.NavigationContent="{Binding Link}" 
                                  Click="_OnNavigateToContentButtonClicked"
                                  IsEnabled="True">
                            <Button.Style>
                              <Style TargetType="Button" BasedOn="{StaticResource AnimatedItemButton}">
                                <Setter Property="Visibility" Value="Collapsed" />
                                <Style.Triggers>
                                  <DataTrigger Binding="{Binding Type}" Value="Links">
                                    <Setter Property="Visibility" Value="Visible" />
                                  </DataTrigger>
                                </Style.Triggers>
                              </Style>
                            </Button.Style>
                            <ClientManagerControls:FacebookImageControl FacebookImage="{Binding Links[0].Image}" FacebookImageDimensions="Small">
                              <ClientManagerControls:FacebookImageControl.Template>
                                <ControlTemplate TargetType="{x:Type ClientManagerControls:FacebookImageControl}">
                                  <Image Stretch="Uniform" Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSource}" />
                                </ControlTemplate>
                              </ClientManagerControls:FacebookImageControl.Template>
                            </ClientManagerControls:FacebookImageControl>
                          </Button>
                        </Grid>
                      </Grid>
                    </DockPanel>
                  </Border>
                </Grid>
              </Grid>
            </DataTemplate>
          </FacebookClient:ZapScroller.ItemTemplate>
        </FacebookClient:ZapScroller>

        <ClientManagerControls:Spinner Foreground="{DynamicResource ToolbarLightIconForegroundBrush}">
          <ClientManagerControls:Spinner.Style>
            <Style TargetType="{x:Type ClientManagerControls:Spinner}">
              <Setter Property="IsRunning" Value="False" />
              <Setter Property="Visibility" Value="Collapsed" />
              <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=PART_ZapScroller2, Path=ItemCount}" Value="0">
                  <Setter Property="IsRunning" Value="True" />
                  <Setter Property="Visibility" Value="Visible" />
                </DataTrigger>
              </Style.Triggers>
            </Style>
          </ClientManagerControls:Spinner.Style>
        </ClientManagerControls:Spinner>

      </Grid>

    </DockPanel>

    <StackPanel x:Name="CaptionArea" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="8,0" Orientation="Horizontal" FlowDirection="RightToLeft">
      <Button Style="{StaticResource CaptionButtonStyle}" Click="_OnRestoreClicked">
        <Button.ToolTip>
          <ToolTip Placement="Left">Go back to Fishbowl</ToolTip>
        </Button.ToolTip>
        <Image Source="Resources\Images\Fishbowl.ico" Margin="2" Width="20" Height="20"/>
      </Button>
      <Button Style="{StaticResource CaptionButtonStyle}" Click="_OnMinimizeClicked">
        <Button.ToolTip>
          <ToolTip Placement="Left">Minimize</ToolTip>
        </Button.ToolTip>
        <Rectangle Margin="2" Height="16" Width="16" Fill="{DynamicResource MinimizeLightDrawingBrush}"/>
      </Button>
    </StackPanel>
  </Grid>
</Window>
